package com.kfm.base.function2;

public class Demo06 {

    public static void main(String[] args) {
        /*
          阶乘
            5! = 5 * 4 * 3 * 2 * 1;
            4! = 4 * 3 * 2 * 1;
            3! = 3 * 2 * 1;
            2! = 2 * 1;
            1! = 1;

            5! =  5 * 4!
         */

        int num = 5;
        int result = factorial(num);
        System.out.println(result);

    }

    public static int factorial(int num) {
        if (num == 1){
            return 1;
        }
//        int result = factorial(num - 1);
//        int s = num * result;
//        return s;

        return num *= factorial(num - 1);
    }
}
